<template>
  <view class="Content">
    <u-navbar
      :is-back="false"
      title="我的"
      :titleBold="true"
    ></u-navbar>
    <view class="header">
      <u-avatar
        mode="circle"
        size="large"
        :show-sex="true"
        :sex-icon="userMsg.gender==false?'man':'woman'"
        style="margin: 0 auto;"
      ></u-avatar>
      <view
        class="u-line-1"
        style="text-align: center;font-size: 14px;font-weight: bold;margin: 10px 0;"
      >{{userMsg.name}}</view>
    </view>
    <view>
      <u-cell-group>
        <u-cell-item
          title="学号"
          :value="userMsg.id"
          :arrow="false"
        ></u-cell-item>
        <u-cell-item
          title="学院"
          :value="userMsg.college"
          :arrow="false"
        ></u-cell-item>
        <u-cell-item
          title="专业"
          :value="userMsg.major"
          :arrow="false"
        ></u-cell-item>
        <u-cell-item
          title="班级"
          :value="userMsg.clazz"
          :arrow="false"
        ></u-cell-item>
        <u-cell-item
          title="邮箱"
          :value="userMsg.qqEmail"
          :arrow="false"
        ></u-cell-item>
      </u-cell-group>
    </view>
    <u-button
      type="error"
      @click="LogOut"
    >退出</u-button>
    <u-toast ref="uToast" />
  </view>
</template>

<script>
export default {
  data () {
    return {
      Token: '',
      StuID: '',
      userMsg: []
    }
  },
  onLoad () {
    let value = uni.getStorageSync('UserMsg')
    if (!value) {
      uni.reLaunch({
        url: '/pages/login/index'
      })
    } else {
      this.Token = value.Token
      this.StuID = value.StuID
    }
  },
  onShow () {
    let _this = this
    this.$u.post('/user/judge/token', {
      token: this.Token
    }).then(res => {
      console.log(res);
      if (res.statusCode == 0) {
        _this.$u.post('/personalCenter/get/personalInformation', {
          id: _this.StuID
        }).then(res => {
          console.log(res)
          _this.userMsg = res.rst
        })
      } else {
        uni.reLaunch({
          url: '/pages/login/index'
        })
      }
    })
  },
  methods: {
    LogOut () {
      let _this = this
      uni.setStorage({
        key: 'UserMsg',
        data: {},
        success: function () {
          uni.reLaunch({
            url: '/pages/login/index'
          })
        }
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.header {
  display: flex;
  flex-direction: column;
  margin: 20px 0;
}
</style>
